/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			iprop.cc
  \date			Oct 2012
  \author		TNick

  \brief		Contains the implementation of IProp class


*//*


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read COPYING and README files in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<cpg/cpg.h>
#include	<QStringList>

#include	<cpg/properties/propbase.h>
#include	<cpg/properties/props.h>

#include	"iprop.h"


/*  INCLUDES    ============================================================ */
//
//
//
//
/*  DEFINITIONS    --------------------------------------------------------- */


/*  DEFINITIONS    ========================================================= */
//
//
//
//
/*  DATA    ---------------------------------------------------------------- */

/*  DATA    ================================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/* ------------------------------------------------------------------------- */
IProp::IProp	( void )
{
	/* stub */
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
IProp::~IProp	( void )
{
	/* stub */
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
QString					IProp::dumpProps			(
		bool b_with_val, bool b_with_info ) const
{
	QStringList	s_ret;

	/* get the properties */
	int		i_max;
	PropIndex * prp_lst = properties( i_max );
	if ( prp_lst == NULL )
	{
		return QObject::tr( "The object has no properties.\n" );
	}

	/* iterate and add properties */
	PropBase * prp_base;
	for ( int i = 0; i < i_max; i++ )
	{
		/* get the instance that handles this */
		prp_base = Props::propBase( prp_lst[i] );
		if ( prp_base == NULL )
		{
			s_ret.append( QObject::tr(
							  "\tThe index %1 represents an invalid property." )
						  .arg( prp_lst[i] )
						  );
		}
		else
		{
			/* print with or without value */
			if ( b_with_val )
			{
				s_ret.append( QObject::tr( "\t> %1 = %3", "a property name in a listing, with value" )
							  .arg( prp_base->name() )
							  .arg( propValueAsString( prp_lst[i], prp_base ) )

							  );
			}
			else
			{
				s_ret.append( QObject::tr( "\t> %1", "a property name in a listing, without value" )
							  .arg( prp_base->name() )
							  );
			}

			/* help user understand what we're doing here */
			if ( b_with_info )
			{
				s_ret.append( QObject::tr( "\t\t%1", "additional information for a property" ) );
			}
		}
	}

	return s_ret.join( "\n" );
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
QString						IProp::propValueAsString		(
		PropIndex idx, const PropBase * prp_base ) const
{

	/* make sure we have a property base */
	if ( prp_base == NULL )
	{
		prp_base = Props::propBase( idx );
		if ( prp_base == NULL )
		{
			return QString();
		}
	}

	/* ask property base to do this for us */
	return prp_base->asString( this, idx );

}
/* ========================================================================= */

/*  CLASS    =============================================================== */
//
//
//
//
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
